//
//  YWNetwork.m
//  百布业务
//
//  Created by 陈炳桦 on 15/10/28.
//  Copyright © 2015年 陈炳桦. All rights reserved.
//

#import "YWNetwork.h"


@implementation YWNetwork

// 正式环境
//static NSString *domain = @"http://biz.baibu.la/app/sm/";

// 测试环境
static NSString *domain = @"http://115.29.247.11:8084/app/sm/";

+ (NSString *)getDomain{
    return domain;
}

// 登录接口
+ (void)loginWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@loginAdmin",domain];
    
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

            successBlock(operation,responseObject);
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
            failureBlock(operation,error);
        }];

}

// 获取通过的需求列表接口
+ (void)selectBuyerDemandWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
     NSString *url = [NSString stringWithFormat:@"%@selectBuyerDemandListByYesStatus",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];

    
}

// 需求、下单、集中采购接口
+ (void)demandListWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/list",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];
    
    
}

// 添加商户接口
+ (void)addSellerWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@addSeller",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];

}

// 处理状态接口
+ (void)handleHistorysWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/handleHistorys",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];

}

// 回复列表接口
+ (void)replysWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/replys",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];
    
}

// 发布需求接口
+ (void)postDemandWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/add",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];
}

// 修改需求接口
+ (void)updateDemandWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/update",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];
}

// 删除或关闭需求接口
+ (void)updateStatusWithParameters:(NSDictionary *)parameters success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))successBlock failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock{
    
    NSString *url = [NSString stringWithFormat:@"%@demand/updateStatus",domain];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic addEntriesFromDictionary:parameters];
    dic[@"workerId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"adminId"] = [YWUserInfo sharedUseInfo].workId;
    dic[@"accessToken"] = [YWUserInfo sharedUseInfo].accessToken;
    
    NSLog(@"%@",dic);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successBlock(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureBlock(operation,error);
    }];
}



@end
